<template>
  <div class="page-department">
    <div class="component-mainHeader">
      <div class="top">
        <div class="topleft">
          <p>
            <span class="iconfont" style="color:#1abc9a;margin-right:3px;">&#xe607;</span>派单记录
          </p>
        </div>
        <div class="topright">
          <el-button type="info" @click="$router.go(0)">
            <span style="font-weight:700;margin-right:5px;" class="iconfont">&#xe662;</span>刷新
          </el-button>
        </div>
      </div>
    </div>
    <!-- 大区负责人 -->
    <div v-if="ms_roleName == 'AreaManager'">
      <div class="component-searchHeader">
        <div class="search-header">
          <div class="left-title">
            <p class="left-text">
              <span class="iconfont">&#xe63d;</span> 筛选查询
            </p>
            <div class="right">
              <button @click="findBigRes">查询</button>
            </div>
          </div>
        </div>
      </div>
      <div class="component-search-box">
        <el-form :inline="true" :model="bigSearch" class="demo-form-inline">
          <el-form-item label="操作日期：">
            <el-date-picker
              v-model="bigSearch.date"
              type="daterange"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="timestamp"
              :default-time="['00:00:00','23:59:59']"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="施工公司：">
            <el-select v-model="bigSearch.name" placeholder="全部" clearable>
              <el-option
                v-for="item in comp"
                :key="item.orgId"
                :label="item.orgName"
                :value="item.orgId"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <div class="component-listHeader">
        <div class="search-header">
          <div class="left-title">
            <p class="left-text">
              <span class="iconfont">&#xe61e;</span>
              {{title}}
            </p>
          </div>
        </div>
      </div>
      <div class="table">
        <el-table
          ref="multipleTable"
          :data="bigInfo"
          tooltip-effect="dark"
          style="width:100%"
          border
        >
          <el-table-column label="编号" align="center" width="50" type="index"></el-table-column>
          <el-table-column label="派单时间" align="center" width="160">
            <template slot-scope="scope">{{scope.row.assignDate | dateFilter}}</template>
          </el-table-column>
          <el-table-column label="工单号" align="center" width="150" prop="bmkRelevanceNo"></el-table-column>
          <el-table-column label="施工公司" align="center" width="150" prop="bmkWorkteam"></el-table-column>
          <el-table-column label="公司负责人" align="center" width="150" prop="userName"></el-table-column>
          <el-table-column label="施工队名称" align="center" width="120" prop="constructTeam"></el-table-column>
          <el-table-column label="工单状态" align="center" width="150" prop="progress"></el-table-column>
          <el-table-column label="操作信息" align="center">
            <template slot-scope="scope">
              <a class="options" @click.prevent="lookDetail(scope.row)">查看详情</a>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页 -->
      <div class="component-paging" v-if="bigInfo.length > 0">
        <div class="table-bottom">
          <div class="bottom-left" style="margin-left: 42px;"></div>
          <div class="paging">
            <div class="paging-left">
              <p>
                共
                <span>{{Math.ceil(Page.RowCount/Page.PageSize)}}</span> 页/
                <span>{{Page.RowCount}}</span> 条数据
              </p>
            </div>
            <el-pagination
              background
              @size-change="SizeChange($event,bigDataInit,Page.CurrentPage,Page.PageSize)"
              @current-change="CurrentChange($event,bigDataInit,Page.CurrentPage,Page.PageSize)"
              :current-page.sync="Page.CurrentPage"
              :page-sizes="[10, 20, 30]"
              :page-size.sync="Page.PageSize"
              layout="sizes, prev, pager, next, jumper"
              :total="Page.RowCount"
            ></el-pagination>
          </div>
        </div>
      </div>
      <!--查看详情弹窗-->
      <div class="component-models">
        <el-dialog title="查看详情" :visible.sync="dialogDetail.flag" width="660px">
          <el-form :model="dialogDetail.info" ref="dialogDetail.info" label-width="200px" class="demo-ruleForm">
            <el-form-item label="施工公司:">
              <span style="float: left;">{{dialogDetail.info.bmkWorkteam}}</span>
            </el-form-item>
            <el-form-item label="公司负责人:">
              <span style="float: left;">{{dialogDetail.info.userName}}</span>
            </el-form-item>
            <el-form-item label="委派施工队:">
              <span style="float: left;">{{dialogDetail.info.constructTeam}}</span>
            </el-form-item>
            <el-form-item label="备注:">
              <span style="float: left;">{{dialogDetail.info.dispatchRemark}}</span>
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="dialogDetail.flag = false">关闭</el-button>
          </span>
        </el-dialog>
      </div>
    </div>

    <!-- 施工公司 -->
    <div v-if="ms_roleName == 'WorkTeamManager'">
      <el-tabs
        v-model="activeName"
        type="border-card"
        @tab-click="handleClick"
        class="tabs-header"
        style="width:1150px;margin:20px auto 0"
      >
        <el-tab-pane label="未接单" name="first">
          <div class="component-searchHeader">
            <div class="search-header">
              <div class="left-title">
                <p class="left-text">
                  <span class="iconfont" style="font-weight:700">&#xe63d;</span>筛选查询
                </p>
                <div class="right">
                  <button @click="searchInfo()">查询</button>
                </div>
              </div>
            </div>
          </div>

          <div class="component-search-box">
            <el-form :inline="true" :model="compSearch" class="demo-form-inline">
              <el-form-item label="输入搜索：">
                <el-input
                  v-model="compSearch.info"
                  placeholder="工单号"
                  clearable
                  style="width:217px;"
                ></el-input>
              </el-form-item>
              <el-form-item label="工单委托日期：" style="width:330px;">
                <el-date-picker
                  v-model="compSearch.date"
                  type="date"
                  placeholder="选择日期"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="timestamp"
                  style="width:217px;"
                  default-time="00:00:00"
                ></el-date-picker>
              </el-form-item>
            </el-form>
          </div>

          <div class="component-listHeader">
            <div class="search-header">
              <div class="left-title">
                <p class="left-text">
                  <span class="iconfont">&#xe61e;</span>
                  派单列表
                </p>
                <div class="right"></div>
              </div>
            </div>
          </div>

          <div class="table">
            <el-table
              ref="multipleTable"
              :data="compInfo"
              tooltip-effect="dark"
              style="width: 1100px;margin:0 auto"
              border
            >
              <el-table-column label="工单号" align="center" width="170" prop="bmkRelevanceNo"></el-table-column>
              <el-table-column label="五级地址" align="center" width="170" prop="bmkStation"></el-table-column>
              <el-table-column label="施工队" align="center" width="170" prop="constructTeam"></el-table-column>
              <el-table-column label="派单日期" align="center" width="170" prop="assignDate">
                <template slot-scope="scope">{{scope.row.assignDate|timeFilter}}</template>
              </el-table-column>
              <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                  <el-button
                    @click="$router.push({name:'expansionDetail',params:{proId:scope.row.proId}})"
                    type="text"
                    size="small"
                    class="red"
                  >查看详情</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="component-paging" v-show="compInfo.length>0">
            <div class="table-bottom">
              <div class="bottom-left">
                <!-- <button @click="outputData" style="width:130px;">生成紧急扩容资料</button>
                <button @click="outputTotal" style="width:110px;">生成统计总表</button>-->
              </div>
              <div class="paging">
                <div class="paging-left">
                  <p>
                    共
                    <span>{{Math.ceil(compPage.RowCount/compPage.PageSize)}}</span> 页/
                    <span>{{compPage.RowCount}}</span> 条数据
                  </p>
                </div>
                <el-pagination
                  background
                  @size-change="SizeChange($event,compDataInit,compPage.CurrentPage,compPage.PageSize)"
                  @current-change="CurrentChange($event,compDataInit,compPage.CurrentPage,compPage.PageSize)"
                  :current-page.sync="compPage.CurrentPage"
                  :page-sizes="[10, 20, 30]"
                  :page-size.sync="compPage.PageSize"
                  layout="sizes, prev, pager, next, jumper"
                  :total="compPage.RowCount"
                ></el-pagination>
              </div>
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="已接单" name="second">
          <div class="component-searchHeader">
            <div class="search-header">
              <div class="left-title">
                <p class="left-text">
                  <span class="iconfont" style="font-weight:700">&#xe63d;</span>筛选查询
                </p>
                <div class="right">
                  <button @click="searchInfo()">查询</button>
                </div>
              </div>
            </div>
          </div>

          <div class="component-search-box">
            <el-form :inline="true" :model="compSearch" class="demo-form-inline">
              <el-form-item label="输入搜索：">
                <el-input
                  v-model="compSearch.info"
                  placeholder="工单号"
                  clearable
                  style="width:217px;"
                ></el-input>
              </el-form-item>
              <el-form-item label="工单委托日期：" style="width:330px;">
                <el-date-picker
                  v-model="compSearch.date"
                  type="date"
                  placeholder="选择日期"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="timestamp"
                  style="width:217px;"
                  default-time="00:00:00"
                ></el-date-picker>
              </el-form-item>
            </el-form>
          </div>

          <div class="component-listHeader">
            <div class="search-header">
              <div class="left-title">
                <p class="left-text">
                  <span class="iconfont">&#xe61e;</span>
                  派单列表
                </p>
                <div class="right"></div>
              </div>
            </div>
          </div>

          <div class="table">
            <el-table
              ref="multipleTable"
              :data="compInfo"
              tooltip-effect="dark"
              style="width: 1100px;margin:0 auto"
              border
            >
              <el-table-column label="工单号" align="center" width="170" prop="bmkRelevanceNo"></el-table-column>
              <el-table-column label="五级地址" align="center" width="170" prop="bmkStation"></el-table-column>
              <el-table-column label="施工队" align="center" width="170" prop="constructTeam"></el-table-column>
              <el-table-column label="派单日期" align="center" width="170" prop="assignDate">
                <template slot-scope="scope">{{scope.row.assignDate|timeFilter}}</template>
              </el-table-column>
              <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                  <el-button
                    @click="$router.push({name:'expansionDetail',params:{proId:scope.row.proId}})"
                    type="text"
                    size="small"
                    class="red"
                  >查看详情</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="component-paging" v-show="compInfo.length>0">
            <div class="table-bottom">
              <div class="bottom-left">
                <!-- <button @click="outputData" style="width:130px;">生成紧急扩容资料</button>
                <button @click="outputTotal" style="width:110px;">生成统计总表</button>-->
              </div>
              <div class="paging">
                <div class="paging-left">
                  <p>
                    共
                    <span>{{Math.ceil(compPage.RowCount/compPage.PageSize)}}</span> 页/
                    <span>{{compPage.RowCount}}</span> 条数据
                  </p>
                </div>
                <el-pagination
                  background
                  @size-change="SizeChange($event,compDataInit,compPage.CurrentPage,compPage.PageSize)"
                  @current-change="CurrentChange($event,compDataInit,compPage.CurrentPage,compPage.PageSize)"
                  :current-page.sync="compPage.CurrentPage"
                  :page-sizes="[10, 20, 30]"
                  :page-size.sync="compPage.PageSize"
                  layout="sizes, prev, pager, next, jumper"
                  :total="compPage.RowCount"
                ></el-pagination>
              </div>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script>
export default {
  name: "operation",
  data() {
    return {
      activeName: "first",
      ms_roleName: localStorage.getItem("roleName"),
      title: "数据列表",

      // 查看详情弹窗
      dialogDetail: {
        flag: false,
        info: {}
      },

      // 大区负责人 表格数据
      bigInfo: [],
      // 大区负责人 分页
      Page: {
        CurrentPage: 1,
        PageSize: 10,
        RowCount: 1
      },
      // 大区负责人-查询条件
      bigSearch: {
        date: [],
        name: ""
      },
      // 大区负责人 - 下拉框数据
      comp: [],

      // 施工公司表格
      compInfo: [{}],
      // 施工公司 分页
      compPage: {
        CurrentPage: 1,
        PageSize: 10,
        RowCount: 1
      },
      // 施工公司 查询条件
      compSearch: {
        info: "",
        date: ""
      },
    };
  },
  created() {},
  mounted() {
    if (this.ms_roleName == "WorkTeamManager") {
      this.compDataInit();
    } else if (this.ms_roleName == "AreaManager") {
      this.compSelection();
      this.bigDataInit();
    }
  },
  methods: {
    findRes() {
      this.currentPage = 1;
      this.dataInit();
    },

    // 大区负责人角色

    // 施工公司下拉框
    compSelection() {
      let that = this,
        suCb = res => {
          console.log(res);
          that.comp = res.data.data;
        },
        erCb = res => {},
        req = {
          url: "/api/web/sysOrg/getSubordinateOrgList",
          methods: "post",
          data: {},
          success: suCb,
          error: erCb
        };
      that.$https(req);
    },

    // 大区负责人数据表格
    bigDataInit() {
      let dateArr = ["", ""];
      if (this.bigSearch.date != undefined) {
        dateArr = this.bigSearch.date;
      }
      let that = this,
        suCb = res => {
          console.log(res);
          that.bigInfo = res.data.data;
          that.Page.RowCount = res.data.rowCount;
        },
        erCb = res => {},
        req = {
          url: "/api/web/proProject/selectOrdersByBmkArea",
          methods: "post",
          data: {
            startDate: dateArr[0] != undefined ? dateArr[0] + "" : "",
            endDate: dateArr[1] != undefined ? dateArr[1] + "" : "",
            bmkWorkteam: that.bigSearch.name,
            pageSize: that.Page.PageSize,
            pageCurrent: that.Page.CurrentPage
          },
          success: suCb,
          error: erCb
        };
      that.$https(req);
    },
    // 大区负责人查看详情
    lookDetail(row) {
      this.dialogDetail = {
        flag: true,
        info: row
      };
    },
    // 大区负责人 查询按钮
    findBigRes() {
      this.Page.CurrentPage = 1;
      this.bigDataInit();
    },

    // 施工公司角色

    // 施工公司数据表格
    compDataInit() {
      let that = this,
        suCb = res => {
          console.log(res);
          that.compInfo = res.data.data;
          that.compPage.RowCount = res.data.rowCount;
        },
        erCb = res => {},
        req = {
          url: "/api/web/proProject/selectOrdersByBmkWorkteam",
          methods: "post",
          data: {
            assignDate: that.compSearch.date+'',
            bmkRelevanceNo: that.compSearch.info,
            pageSize: that.compPage.PageSize,
            pageCurrent: that.compPage.CurrentPage
          },
          success: suCb,
          error: erCb
        };
      req.data.acceptStatus = that.activeName == "first" ? "1" : "2";
      that.$https(req);
    },
    // 施工公司 查询按钮
    searchInfo() {
      this.compPage.CurrentPage = 1;
      this.compDataInit();
    },
    // 施工公司 - 切换选项卡
    handleClick() {
      if (this.activeName == "first") {
      } else {
      }
      this.compPage.CurrentPage = 1;
      this.compDataInit();
    }
  }
};
</script>

<style scoped>
.component-searchHeader .search-header {
  width: 1100px;
  box-sizing: border-box;
  border: 1px solid rgba(228, 228, 228, 1);
  background-color: rgba(255, 255, 255, 1);
  margin: 20px auto 0;
}

.component-searchHeader .search-header .left-title {
  display: flex;
  justify-content: space-between;
  width: 100%;
  background-color: rgba(243, 243, 243, 1);
  height: 45px;
  box-sizing: border-box;
}

.component-searchHeader .search-header .left-title .left-text {
  width: 20%;
  color: #666;
  line-height: 45px;
  font-family: "微软雅黑";
  font-weight: 400;
  font-size: 12px;
  text-align: left;
  margin: 0 0 0 30px;
}

.component-searchHeader .right {
  width: 70%;
  display: flex;
  justify-content: flex-end;
  margin-right: 30px;
}

.component-searchHeader .right button {
  padding: 0 15px;
  height: 30px;
  margin: 6px 5px;
  line-height: 30px;
  font-size: 12px;
  color: #666;
  background-color: #fff;
  border: 1px solid #ccc;
}

.component-searchHeader .right button:hover {
  background-color: #f3f3f3;
}

.component-search-box {
  width: 1100px;
  height: 60px;
  box-sizing: border-box;
  background-color: #fff;
  border: 1px solid #e4e4e4;
  border-top: none;
  margin: 0 auto;
  text-align: left;
  padding-left: 30px;
  line-height: 60px;
}

.component-search-box .el-input__inner {
  height: 36px;
  display: inline-block;
  vertical-align: middle;
}

.component-listHeader .search-header {
  width: 1100px;
  box-sizing: border-box;
  border: 1px solid rgba(228, 228, 228, 1);
  background-color: rgba(255, 255, 255, 1);
  margin: 20px auto 0;
  border-bottom: 0;
}

.component-listHeader .search-header .left-title {
  display: flex;
  justify-content: space-between;
  width: 100%;
  background-color: rgba(243, 243, 243, 1);
  height: 45px;
  box-sizing: border-box;
}

.component-listHeader .search-header .left-title .left-text {
  width: 20%;
  color: #666;
  line-height: 45px;
  font-family: "微软雅黑";
  font-weight: 400;
  font-size: 12px;
  text-align: left;
  margin: 0 0 0 30px;
}

.component-listHeader .search-header .right {
  width: 70%;
  display: flex;
  justify-content: flex-end;
  margin-right: 10px;
}

.component-listHeader .search-header .right button {
  padding: 0 15px;
  height: 30px;
  width: 80px;
  margin: 6px 5px;
  line-height: 30px;
  font-size: 14px;
  color: #666;
  background-color: #fff;
  border: 1px solid #ccc;
}

.component-listHeader .search-header .right button:hover {
  background-color: #f3f3f3;
}

.component-listHeader .search-header .right .right-select-margin {
  margin-top: 6px;
  margin-right: 8px;
}

.component-table-header {
  width: 1100px;
  margin: 0 auto;
  display: flex;
  border: 1px solid #e4e4e4;
  background-color: #f9fafc;
  height: 45px;
  line-height: 45px;
  padding: 0;
  list-style: none;
  justify-content: space-between;
  box-sizing: border-box;
  border-top: none;
}

.component-table-header li:first-child {
  width: 50px;
}

.component-table-header li:first-child span {
  border-radius: 5px;
  border: 2px solid #aba2a2;
  display: inline-block;
  width: 16px;
  height: 16px;
  margin: 12.5px auto;
  line-height: 16px;
  font-size: 16px;
}

.component-table-header li {
  border-right: 1px solid #e4e4e4;
  font-family: "PingFangSC-Semibold", "PingFang SC Semibold", "PingFang SC";
  font-weight: 650;
  font-style: normal;
  font-size: 14px;
  color: #666666;
}
.component-table-header li:last-child {
  border: none;
}

.component-table-body {
  width: 1100px;
  margin: 0 auto;
  display: flex;
  border: 1px solid #e4e4e4;
  background-color: #fff;
  height: 45px;
  line-height: 45px;
  padding: 0;
  list-style: none;
  justify-content: space-between;
  box-sizing: border-box;
  border-top: none;
}

.component-table-body li {
  font-size: 12px;
  color: #666;
  text-align: center;
  border-right: 1px solid #e4e4e4;
}

.component-table-body li:first-child {
  width: 50px;
}

.component-table-body li:nth-child(2) {
  width: 100px;
}

.component-table-body li:nth-child(3) {
  width: 150px;
}

.component-table-body li:nth-child(4) {
  width: 150px;
}
.component-table-body li:nth-child(5) {
  width: 150px;
}

.component-table-body li:last-child {
  width: 500px;
  border-right: none;
}

.component-table-body li:last-child {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  padding: 0 auto;
}

.component-table-body li:last-child a {
  display: inline-block;
  text-align: center;
  color: #1abc9c;
  text-decoration: none;
  font-size: 12px;
}

/* 下面都是修改饿了么ui的下拉框和按钮选中后的样式 */

.el-select .el-input.is-focus .el-input__inner,
.el-select .el-input__inner:focus {
  border-color: #e4e4e4;
}

.el-select-dropdown__item.selected {
  color: #666;
  font-weight: 400;
}

.el-select-dropdown {
  min-width: 100px !important;
  top: 50px !important;
  margin-left: 5px;
}
.el-select-dropdown__item {
  height: 26px;
  line-height: 26px;
}

.el-select .el-input__inner {
  width: 100px;
  padding: 0 8px;
  margin: 6px 5px;
}
.component-paging .table-bottom .all-left button {
  background-color: #fff;
}
.component-paging .table-bottom .all-left button:hover {
  background-color: #f3f3f3;
}

.table {
  width: 1100px;
  margin: 0 auto;
}
.options {
  color: #1abc9c;
  padding: 0 5px;
  cursor: pointer;
}
.el-textarea {
  width: 220px;
  vertical-align: top;
}

.component-models .el-form-item {
  width: 512px;
  margin-bottom: 10px;
}
.component-models .el-select {
  left: -50px;
}
</style>
